<?php
if (!defined('access')) {
    echo 'You cannot access this file directly.';
    exit();
}
@unlink("/tmp/test.xml");
@unlink("/tmp/subotage.tmp");
function search_sub($file){
    $parts = pathinfo($file);
    $escapedBracketPath = str_replace('[', '\[', $parts['dirname']);
    $escapedBracketPath = str_replace(']', '\]', $escapedBracketPath);
    $escapedBracketPath = str_replace('\[', '[[]', $escapedBracketPath);
    $escapedBracketPath = str_replace('\]', '[]]', $escapedBracketPath);
    $shortest = -1;
    foreach (glob($escapedBracketPath . "/*.[sStT][rRuUxX][tTbBtT]") as $subs) {
             $lev = levenshtein($file, $subs);
             if ($lev == 0) {
	      $file_out = $subs;
	      $shortest = 0;
	      break;
	      }
	      if ($lev <= $shortest || $shortest < 0) {
	      $file_out  = $subs;
	      $shortest = $lev;
	      }
        }
    return $file_out;
}
if ($this->Jukebox_Size == "nexturl") {
    $file1 = file_get_contents("/tmp/nexturl");
    $file = search_sub($file1);
} else {
    if(!$file_full){
        $file_full = $this->category_title;
    }
    $file = search_sub($file_full);
}
$file = str_replace(
        array(" ", "'", "(", ")", "&"),
        array("\\ ", "\\'", "\\(", "\\)", "\&"),
        html_entity_decode($file));
exec("/usr/local/etc/subotage.sh -of xml -i $file -o /tmp/pre_test.xml");
$this->sub_encode();
/*if (!preg_match("/www\/cgi-bin\/scripts\/util/", $this->read_config('font_type'))){
    $encoding = exec("/opt/bin/file -b --mime-encoding /tmp/pre_test.xml");
    file_put_contents("/tmp/enc", $encoding);
    if($encoding == "iso-8859-1" || preg_match("/unknown/", $encoding)){
        $encoding = "iso-8859-2";
    }
    exec("/opt/bin/iconv -f $encoding -t utf-8 /tmp/pre_test.xml > /tmp/test.xml");
    //exec("/opt/bin/recode l2..utf8 /tmp/test.xml");
} */

